<template>
  <div>
    <erpForm :props_cols="cols_data" :model="formData" ref="formRef"
     :props_ignore_cols="['dic_id']"
    >
      <el-form-item label="字典名称" >
        <el-input v-model="formData['dicParentName']" :disabled="true"></el-input>
      </el-form-item>
    </erpForm>
  </div>
</template>
<script>
import erpForm from '@/components/erpform/erpform.vue';
import { cols_data, baseFormData } from './_utils';
import { cloneDeep as deepClone } from 'lodash-es';
import { alertWithPaylod } from '@/utils/alertUtils';
import axios from 'axios';

export default {
  components: {
    erpForm,
  },
  data() {
    return {
      cols_data,
      formData: {
       ...deepClone(baseFormData),
        dicParentName: '',
        dic_id: '',

      },
    };
  },
  methods: {
    initByDialog(_data) {



      if (_data && _data.id) {
        this.formData = _data;

      }


if(!this.formData?.dic_id ){
  this.formData.dic_id = _data?.parentRow?.id;
  this.formData.dicParentName = _data?.parentRow?.name;
}

      this.$refs['formRef'].initByDialog({ formData: this.formData });


    },
    async submitByDialog() {
      var paramsresult = this.$refs['formRef'].submitByDialog();
      if (!paramsresult?.success) {
        return paramsresult;
      }
      var parmas = paramsresult?.data;
      delete parmas.dicParentName
      var resylt = await axios
          .post('/api/tb_dictdetails/apis', {
            _name: 'addorupdate',
            ...parmas,
          })
          .then((res) => res.data);
      console.log('resylt :', resylt);
      alertWithPaylod(resylt);

      return resylt;
    },
  },
};
</script>
